/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mrs.models;

import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import mrs.database.*;

/**
 *
 * @author pablo
 */
public class Recipe {

  public static String RECIPES_FOLDER = "\\data\\recipe_files\\";

  public int id;
  public String title;
  public String servings;
  public String directions;


  public Recipe(String title) {
    this.title = title;
  }

  public Recipe(String title, String servings) {
    this.title = title;
    this.servings = servings;
  }



  public Recipe(
          String title,
          String servings,
          String directions) {
    this.title = title;
    this.servings = servings;
    this.directions = directions;
  }

  @Override
  public String toString() {
    return this.title;
  }


//  public static Recipe fromRecipeMLFile(String fileName)
//  {
//
//  }

  public static Vector<File> getRecipeFiles()
  {
    Vector<File> recipesFileList = new Vector<File>();

    File recipesDirectory = new File(System.getProperty("user.dir") + Recipe.RECIPES_FOLDER);
    File[] recipeFiles = recipesDirectory.listFiles();

    for(File recipeFile:recipeFiles)
    {
        if (recipeFile.isFile() && recipeFile.getName().endsWith(".xml"))
        {
            recipesFileList.add(recipeFile);
        }
    }

    return recipesFileList;
  }

//  public static ArrayList getAll() throws Exception {
//    try {
//
//      ArrayList recipes = new ArrayList();
//      Recipe recipe;
//
//      Statement stat = DB.connect().createStatement();
//      ResultSet rs = stat.executeQuery("select * from Recipe;");
//
//      while (rs.next()) {
//        recipe = new Recipe(rs.getInt("id"),
//                            rs.getString("name"),
//                            rs.getInt("servings"),
//                            rs.getInt("time_minutes"),
//                            rs.getInt("difficulty"),
//                            rs.getInt("price"),
//                            rs.getString("directions"));
//        recipes.add(recipe);
//        System.out.println(recipe);
//      }
//
//      rs.close();
//      DB.disconnect();
//
//      return recipes;
//
//    } catch (SQLException ex) {
//      Logger.getLogger(Recipe.class.getName()).log(Level.SEVERE, null, ex);
//      return null;
//    }
//  }
}
